package com.app.dao;

import com.app.pojo.UserInfo;
import com.app.pojo.UserPassword;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserDao {

    /*----------------UserInfo--------------------*/
    @Select("SELECT * FROM user_info WHERE username = #{username}")
    UserInfo finUserInfoByName(String username);
    @Select("SELECT * FROM user_info WHERE email = #{email}")
    UserInfo finUserInfoByEmail(String email);
    @Select("SELECT * FROM user_info WHERE userId = #{userId}")
    UserInfo finUserInfoById(String userId);

    /*----------------userId--------------------*/
    @Select("SELECT userId FROM user_info WHERE email = #{email}")
    String finUserIdByEmail(String username);
    @Select("SELECT userId FROM user_info WHERE username = #{username}")
    String finUserIdByName(String username);
    /*----------------密码--------------------*/
    @Select("SELECT password FROM user_pw WHERE userId = #{userId}")
    String finPasswdById(String userId);


    /*----------------insert--------------------*/
    int addUser(UserInfo userInfo);


    /*----------------delete--------------------*/

    int deleteUser(String userId);

    /*----------------labels--------------------*/

    @Select("SELECT label FROM user_labels WHERE userId = #{userId}")
    String[] findLabelsByUserId(String userId);

    @Insert("INSERT INTO user_labels(userId,label) VALUES (#{userId},#{label})")
    int addLabel(String userId, String label);

    @Delete("DELETE FROM user_labels WHERE userId = #{userId} AND label = #{label}")
    int deleteLabel(String userId, String label);

    @Delete("DELETE FROM user_labels WHERE userId = #{userId}")
    int deleteLabelsById(String userId);


    @Insert("INSERT INTO user_info(userId,username,email) VALUES (#{userId},#{username},#{email})")
    int addUserInfo(String userId,String username,String email);

    @Insert("INSERT INTO user_pw(userId,password) VALUES (#{userId},#{password})")
    int addUserPw(String userId,String password);
}
